﻿

<?php
function capnhat()
	{
	

	$con=mysql_connect("localhost","root","") or die("Không thể kết nối đến Server");
	//Chon CSDL QLSV
	mysql_select_db("clock",$con) or die("khong ket noi CSDL duoc");
	
	mysql_query("set names 'utf8'");
	
	$ma=$_POST["ma"];
	
	$maloai=$_POST["maloai"];
	$tenloai=$_POST["tenloai"];
	
	
		/*
		echo $mssv;
		echo $hoten;
		echo $ngaysinh;
		echo $diachi;
		echo $sdt;
		echo $makhoa;
		mysql_close($con);
		*/
	//Thuc hien cau truy van
	$query="update loai set maloai='".$maloai."',tenloai='".$tenloai."' where maloai='".$ma."'";
    
	//echo $query;

	mysql_query($query,$con);

}
	
?>

<?php

$ma=$_REQUEST["ma"];
//echo $ma;

$con=mysql_connect("localhost","root","") or die("Khong the ket noi voi MySQL");
	//Chon CSDL QLSV
	mysql_select_db("clock",$con) or die("khong ket noi CSDL duoc");
	
	//Chon bang ma la unicode utf-8
	mysql_query("set names 'utf8'");
	
	//Thuc hien cau truy van
	$query="select * from loai where maloai='".$ma."'";
	$result=mysql_query($query,$con);


	$row = mysql_fetch_array($result);
	
		
		$maloai=$row['maloai'];
		$tenloai=$row['tenloai'];
		
		
		/*	
			echo $mssv;
		echo $hoten;
		echo $ngaysinh;
		echo $diachi;
		echo $sdt;
		echo $makhoa;
		*/
		mysql_close($con);
		

			
	if(isset($_POST["update"]))
	{
		capnhat();
		header("location:loai.php");
	}
?>


  <tr>
    <td width="800" height="200" valign="top">
	<form name="form1" method="post" action="updateloai.php">
     <table border="1">
       <!--DWLayoutTable-->
	 <caption><h2>CẬP NHẬT LOẠI SẢN PHẨM</h2></caption>
	 <TR align="center" height="30" bgcolor="#CCCCCC" >
	 <TD width="87" valign="top">MÃ LOẠI</TD>
	 <TD width="139" valign="top"> TÊN LOẠI</TD>
	  </TR>
	 
	 
	  <TR align="center"  valign="middle" bgcolor="#FFFFCC">
	 <TD width="68" height="42" valign="top"><input type="text" name="maloai" value="<?php echo $maloai?>"></TD>
	 <TD width="139" valign="top"><input type="text" name="tenloai" value="<?php echo $tenloai?>"></TD>
	 </TR>
	 </table>
	 <input type="hidden" name="ma" value="<?php echo $ma?>">
	 <input type="submit" name="update" value="Cập nhật" >
    </form></td>
  </tr>
 
 

    

